layui.use(['form'], function(){

	var form = layui.form;

	//监听提交
	form.on('submit(ok)', function(data){
		var url = "<#if package.ModuleName??>/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>/save";
		return CommonUtil.layuiEditPageSaveOnSubmit(url,data.field,"search");
	});

	//表单验证 value：表单的值、item：表单的DOM对象
	form.verify({
	<#list fields as field>
		${field.propertyName}: function(value, item){ 
			if(CommonUtil.isEmpty(value)){
				return '${field.comment}不能为空';
			}
			<#if field.propertyType=='Integer'>
			if(!/^[1-9]+[0-9]*$/.test(value)){
				return '${field.comment}只能输入整数';
			}
			<#elseif field.propertyType=='String'>
			if(value.length > ${field.maxLength}){
				return '${field.comment}长度必须小于${field.maxLength}';
			}
			<#elseif field.propertyType=='Double'||field.propertyType=='Decimal'||field.propertyType=='Float'>
			if(!/^[0-9]{0,${field.maxLength-field.decimalLength}(.[0-9]{0,${field.decimalLength}})?$/.test(value)){
				return '${field.comment}最大只能由${field.maxLength-field.decimalLength}位整数和${field.decimalLength}位小数组成';
			}
			</#if>
		},
	</#list>
	});  
});